#include "Faculty_t.h"
#include "University_t.h"

University_t University_t::m_instance;

University_t::~University_t()
{
	FacultyContainer::const_iterator it = m_faculties.begin();
	for(; it != m_faculties.end(); it++)
		delete it->second;
	m_faculties.clear();
}

University_t& University_t::instance()
{
	return m_instance;
}

bool University_t::addFaculty(Faculty_t* const faculty)
{
	if(findFaculty(faculty->name()) != NULL)
		return false;

	m_faculties.insert(std::make_pair(faculty->name(), faculty));
	return true;
}

Faculty_t* University_t::findFaculty(const std::string& name) const
{
	FacultyContainer::const_iterator it = m_faculties.find(name);
	if(it == m_faculties.end())
		return NULL;

	return it->second;
}

void University_t::notifyPriceRaised() const
{
	// For each faculty - notify price raised [Bridge]
	FacultyContainer::const_iterator it = m_faculties.begin();
	for(; it != m_faculties.end(); it++)
		it->second->notifyPriceRaised();
}

void University_t::notifyLectureCanceled() const
{
	// For each faculty - notify lecture canceled [Bridge]
	FacultyContainer::const_iterator it = m_faculties.begin();
	for(; it != m_faculties.end(); it++)
		it->second->notifyLectureCanceled();
}

University_t::University_t()
{
}